// https://www.acwing.com/problem/content/832/

#include <iostream>
using namespace std;

constexpr int ARRAY_MAX_SIZE = 100010;

int nums[ARRAY_MAX_SIZE];
int curr = 0;

int main() {
    int n, x;
    cin>>n;
    while (n-->0) {
        cin>>x;
        while (curr > 0 && nums[curr] >= x) {
            curr--;
        }
        if (curr == 0) {
            cout<<"-1 ";
        } else {
            cout<<nums[curr]<<" ";
        }
        nums[++curr] = x;
    }

    return 0;
}
